package com.atguigu.juc02;


import java.util.concurrent.*;


class MyCallable implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "888");
        return 666;
    }
}


/**
 * @auther zzyy
 * @create 2020-03-28 16:30
 * java里面，第三种获得多线程的方式
 * 一个新的接口，Callable
 */
public class CallableDemo2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        new Thread(() -> {
//            System.out.println(Thread.currentThread().getName() + "666");
//        }, "Runnable");


//        RunnableFuture<Integer> rf = new FutureTask(() -> {
//            System.out.println(Thread.currentThread().getName() + "888");
//            return 666;
//        });

        RunnableFuture<Integer> rf = new FutureTask(() -> 666);

        new Thread(rf, "c1").start();

        System.out.println(rf.get());


    }
}